<template>
  <div class="search-bar">
    <el-form :inline="true" :model="formItem" class="form-filter" size="mini">
      <el-form-item>
        <el-select v-model="formItem.s_status" clearable placeholder="请选择状态" @change="statusChange">
          <el-option v-for="item in inventoryResultStatus" :key="item.code" :label="item.text" :value="item.code" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="formItem.s_name" clearable placeholder="请输入资产名称..." />
      </el-form-item>
      <el-form-item>
        <el-button plain icon="el-icon-search" @click="search" />
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { status } from '@neu/dcam-ui/api/inventoryResult'
// 定义一个查询表单原始项
const formItem = {
  s_name: '',
  s_status: '',
  s_dutyId: '',
  s_planId: '',
  s_dutyStatus: ''
}

export default {
  name: 'InventoryResultTableFilter',
  props: {
    // 查询按钮会通过属性filter，进行api操作
    filter: {
      required: true,
      type: Function
    },
    dutyStatus: {
      type: Boolean,
      default: null
    }
  },
  data() {
    return {
      formItem: {
        ...formItem
      },
      /** 盘点状态 */
      inventoryResultStatus: [],
      s_dutyId: this.$route.query.dutyId ? this.$route.query.dutyId : '',
      s_planId: this.$route.query.planId ? this.$route.query.planId : '',
      s_status: this.$route.query.status ? this.$route.query.status : ''
    }
  },
  created() {
    // 获取盘点计划状态
    status().then(res => { this.inventoryResultStatus = res.data })
  },
  methods: {
    // 查询按钮点击事件处理
    search: function() {
      this.formItem.s_planId = this.$route.query.planId ? this.$route.query.planId : ''
      this.formItem.s_dutyId = this.$route.query.dutyId ? this.$route.query.dutyId : ''
      this.formItem.s_dutyStatus = 'finish'
      this.filter(this.formItem)
    },
    // 重置按钮点击事件处理
    reset: function() {
      this.formItem = {
        ...formItem
      }
      this.search()
    },
    statusChange: function() {
      this.search()
    }
  }
}
</script>
